package com.f5.management.service.impl;

import com.f5.management.dao.TollDAO;
import com.f5.management.entity.Toll;
import com.f5.management.service.TollService;
import com.f5.management.utils.DeviceUtil;
import com.f5.management.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TollServiceImpl implements TollService {

    @Autowired
    private TollDAO tollDAO;

    @Override
    public boolean add(Toll toll) {
        //自动生成编号
        toll.setChargeNum(DeviceUtil.createTollCharge());
        return tollDAO.insert(toll) > 0 ? true : false;
    }

    @Override
    public PageResult<List<Toll>> findByPage(int page, int size) {
        PageResult<List<Toll>> result = new PageResult<List<Toll>>();
        Page<Toll> startPage = PageHelper.startPage(page, size);
        List<Toll> tolls = tollDAO.findByPage();
        result.setCurrentPage(page);
        result.setSize(size);
        result.setTotal(startPage.getTotal());
        result.setTotalPage(startPage.getPages());
        result.setData(tolls);

        System.out.println(tolls);
        return result;
    }
    @Override
    public Integer findCidByName(String communityName) {

        return tollDAO.findCidByName(communityName);
    }

    @Override
    public Toll findById(int id) {

        return tollDAO.findById(id);
    }

    @Override
    public boolean updateInfo(Toll toll) {


        return tollDAO.updateInfo(toll) > 0 ? true : false;
    }

    @Override
    public boolean delInfo(int id) {
        return tollDAO.delInfo(id) > 0 ? true : false;
    }
}
